package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.Department_lxy;
import com.esm.model.User;
import com.esm.service.DeleteDepartmentService_lxy;
import com.esm.serviceimpl.DelDepSerImpl_lxy;

import net.sf.json.JSONObject;

/**
 * 这是一个删除部门的controller类
 * @author LiuXingYu
 *
 */
public class DeleteDepartmentController_lxy extends HttpServlet{
	DeleteDepartmentService_lxy delDepSer=new DelDepSerImpl_lxy();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
      @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	  HttpSession session=req.getSession();
    	  resp.setCharacterEncoding("utf8");
    	  PrintWriter pw=resp.getWriter();
    	  int deptId=Integer.parseInt(req.getParameter("deptId"));
    	  String deptName=req.getParameter("deptName");
    	  String manager=req.getParameter("manager");
    	  String currentName=((User)session.getAttribute("currentUser")).getUname();
    	  Department_lxy tempdepartment=new Department_lxy(deptId);
    	  JSONObject j =new JSONObject();
    	  j.put("value", delDepSer.DeleteDepartment(tempdepartment,currentName));
    	  pw.write(j.toString());
    	  pw.flush();
    	  pw.close();
    }
}
